package Vistas;
import java.util.Vector;
import javax.swing.JLabel;
import javax.swing.JScrollPane;

import javax.swing.JTable;

import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.SwingUtilities;

import Modelos.ClaseReporte;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class FrmListadoProductos extends javax.swing.JFrame {
	private JTable jTable1;
	private DefaultTableModel jTable1Model;
	private JScrollPane jScrollPane1;
	private JLabel Cantidad;
	private JLabel jLabel1;
	private JLabel Nombre;

	/**
	* Auto-generated main method to display this JFrame
	*/
	
	
	public FrmListadoProductos() {
		super();
		initGUI();
	}
	
	public void AgregarPorCantidad(Vector<ClaseReporte> arr,boolean ascendenteCantidad){
		
		int i;
		for(i=0;i<arr.size();i++){
			for(int j=0;j<arr.size()-1;j++){
				
				if(arr.elementAt(j).getSuma()<arr.elementAt(j+1).getSuma()){
					ClaseReporte aux = new ClaseReporte(arr.elementAt(j).getSuma(),arr.elementAt(j).getMonto(),arr.elementAt(j).getNombre());
					arr.setElementAt(arr.elementAt(j+1),j);
					arr.setElementAt(aux,j+1);
					
				}
			}
		}
		if(ascendenteCantidad){
			for(i=0;i<arr.size();i++){
				Vector fila = new Vector();
				fila.add(arr.elementAt(i).getNombre());
				fila.add(arr.elementAt(i).getMonto()+"Bsf");
				fila.add(arr.elementAt(i).getSuma());
				jTable1Model.addRow(fila);
			}	
		}
		else
		{
			for(i=arr.size()-1;i>=0;i--){
				Vector fila = new Vector();
				fila.add(arr.elementAt(i).getNombre());
				fila.add(arr.elementAt(i).getMonto()+"Bsf");
				fila.add(arr.elementAt(i).getSuma());
				jTable1Model.addRow(fila);
			}
		}
		
	}
	
	public void AgregarPorMonto(Vector<ClaseReporte> arr,boolean ascendentemonto){
		int i;
		for(i=0;i<arr.size();i++){
			for(int j=0;j<arr.size()-1;j++){
				
				if(arr.elementAt(j).getMonto()<arr.elementAt(j+1).getMonto()){
					ClaseReporte aux = new ClaseReporte(arr.elementAt(j).getSuma(),arr.elementAt(j).getMonto(),arr.elementAt(j).getNombre());
					arr.setElementAt(arr.elementAt(j+1),j);
					arr.setElementAt(aux,j+1);
					
				}
			}
		}
		if(ascendentemonto){
			for(i=0;i<arr.size();i++){
				Vector fila = new Vector();
				fila.add(arr.elementAt(i).getNombre());
				fila.add(arr.elementAt(i).getMonto()+"Bsf");
				fila.add(arr.elementAt(i).getSuma());
				jTable1Model.addRow(fila);
			}	
		}
		else
		{
			for(i=arr.size()-1;i>=0;i--){
				Vector fila = new Vector();
				fila.add(arr.elementAt(i).getNombre());
				fila.add(arr.elementAt(i).getMonto()+"Bsf");
				fila.add(arr.elementAt(i).getSuma());
				jTable1Model.addRow(fila);
			}
		}
		
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				Nombre = new JLabel();
				getContentPane().add(Nombre);
				Nombre.setText("Nombre");
				Nombre.setBounds(38, 40, 90, 14);
			}
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("Monto");
				jLabel1.setBounds(227, 40, 80, 14);
			}
			{
				Cantidad = new JLabel();
				getContentPane().add(Cantidad);
				Cantidad.setText("Cantidad");
				Cantidad.setBounds(390, 40, 82, 14);
			}
			{
				jScrollPane1 = new JScrollPane();
				getContentPane().add(jScrollPane1);
				jScrollPane1.setBounds(38, 73, 478, 290);
				{
					jTable1Model = new DefaultTableModel(0,3);
					/*		new DefaultTableModel(
							new String[][] { { "One", "Two" }, { "Three", "Four" } },
							new String[] { "Column 1", "Column 2" });*/
							jTable1 = new JTable();
							jScrollPane1.setViewportView(jTable1);
							jTable1.setModel(jTable1Model);
							jTable1.setBounds(545, 12, 114, 185);
							jTable1.setPreferredSize(new java.awt.Dimension(475, 241));
				}
			}
			pack();
			this.setSize(692, 440);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

}
